import java.io.IOException;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;


public final class SecurityLoggers {

	public static final Logger errorLogger = Logger.getLogger("ErrorLogger");
	public static final Logger pageDiscoveryLogger = Logger.getLogger("PageDiscoveryLogger");
	public static final Logger pageGuessingLogger = Logger.getLogger("PageGuessingLogger");
	public static final Logger inputDiscoveryLogger = Logger.getLogger("InputDiscoveryLogger");
	public static final Logger inputFuzzerLogger = Logger.getLogger("InputFuzzerLogger");
	public static final Logger queryStringLogger = Logger.getLogger("queryStringLogger");
	public static final Logger sensitiveDataLogger = Logger.getLogger("sensitiveDataLogger");
	
	private SecurityLoggers() {
	}

	public static final void setupLoggers() {
		setupSecurityFuzzerLogger(errorLogger, "errorLog.txt");
		setupSecurityFuzzerLogger(pageDiscoveryLogger, "pageDiscoveryLog.txt");
		setupSecurityFuzzerLogger(pageGuessingLogger, "pageGuessingLog.txt");
		setupSecurityFuzzerLogger(inputDiscoveryLogger, "inputDiscoveryLog.txt");
		setupSecurityFuzzerLogger(inputFuzzerLogger, "inputFuzzerLog.txt");
		setupSecurityFuzzerLogger(queryStringLogger, "queryStringLog.txt");
		setupSecurityFuzzerLogger(sensitiveDataLogger, "sensitiveDataLog.txt");
	}
	
	private static final void setupSecurityFuzzerLogger(Logger l, String logFileName) {
		final SystemOutConsoleHandler ch = new SystemOutConsoleHandler();
		FileHandler fh = null;
		try {
			fh = new FileHandler(logFileName);
		} catch (SecurityException e1) {
			e1.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		final SimpleFormatter sf = new SimpleFormatter();
		ch.setFormatter(sf);
		fh.setFormatter(sf);
		l.addHandler(ch);	
		l.addHandler(fh);
	}

	private static class SystemOutConsoleHandler extends ConsoleHandler {
		public SystemOutConsoleHandler() {
			setOutputStream(System.out);
		}
	}
	
}
